import React, { useRef, useState } from 'react'
import { useEffect } from 'react'

export default function TestRef() {
    let [count,setCount] = useState(1)
    // 1. 创建ref，赋值为true
    const flagRef = useRef(true) // {current:true}
    useEffect(()=>{
        if(flagRef.current){
            flagRef.current = false;
            return;
        }
        // 以下是componentDidUpdate的执行时机
        console.log('useEffect run')
    })
    return (
        <div>
            <h3>TestRef</h3>
            <p>count: {count}</p>
            <p><button onClick={()=>setCount(count + 1)}>count++</button></p>
        </div>
    )
}
